﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.Business;
using System.Collections.ObjectModel;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for OfferDataAccessTest and is intended
    ///to contain all OfferDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class OfferDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for InsertOffer
        ///</summary>
        [TestMethod()]
        public void InsertOfferTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("Wireless Magic Mouse", "100", "Este mouse de Apple es inalambrico y se conecta a la computadora via bluetooh, te permite hacer un sin fin de funcionalidades", "Electronics", false, "Dollars", user.Id, "1");
            long productId = product.ProductId;
            Random rand = new Random();
            string buyerEmail = "esardaya" + rand.Next(500) + "@hotmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("minombre", "miapellido", 'M',
                                         birthday, buyerEmail, "password123", "password123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User buyer = UserDataAccess.GetUserByEmail(email);
            long buyerId = buyer.Id;
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer offer = new Offer();
            offer.BuyerId = buyerId;
            offer.Message = message;
            offer.OfferDate = offerDate;
            offer.OfferPrice = Convert.ToInt64(offerPrice);
            offer.RelatedProduct = product;
            offer.Status = "Pending";
            OfferDataAccess.InsertOffer(offer);
        }

        /// <summary>
        ///A test for GetASingleOffer
        ///</summary>
        [TestMethod()]
        public void GetASingleOfferTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("celular Nokia usado", "100", "este celular lo ayudara en todo es un samrtphone que tendra siempre lo que requiere es de color negro y tiene muchas funcionalidades", "Electronics", false, "Dollars", user.Id, "1");
            UserRegistrationManager.RegisterUser("Andrea", "Quiroga", 'F', DateTime.Now, "fabi_aqy@hotmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string buyerEmail = "fabi_aqy@hotmail.com"; // TODO: Initialize to an appropriate value
            User buyer = UserDataAccess.GetUserByEmail(buyerEmail);
            long buyerId = buyer.Id;
            long productId = product.ProductId;
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer expected = OfferManager.MakeAOffer(productId, buyerId, offerPrice, offerDate, message);
            Offer actual;
            actual = OfferDataAccess.GetASingleOffer(buyerId, productId);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for ModifySecondOffer
        ///</summary>
        [TestMethod()]
        public void ModifySecondOfferTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("MIU MIU Pink Wallet", "100", "This is the perfect wallet for everyday. It has benn designed for pretty and sassy women that love fashion", "Fashion", false, "Dollars", user.Id, "1");
            Random rand = new Random();
            string buyerEmail = "diroag" + rand.Next(500) + "@hotmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("minombre", "miapellido", 'M',
                                         birthday, buyerEmail, "password123", "password123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User buyer = UserDataAccess.GetUserByEmail(email);
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer offer = OfferManager.MakeAOffer(product.ProductId, buyer.Id, offerPrice, offerDate, message);
            offer.Status = "Accepted";
            OfferDataAccess.ModifySecondOffer(offer);
        }

        /// <summary>
        ///A test for GetOffer
        ///</summary>
        [TestMethod()]
        public void GetOfferTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("Toy Story 2 Original DVD", "10", "sbfjksfksb snflsnlfskf sfnlsnflsnflsfsdkoef dojgdnvkdnvkndkvnkdvd snfsnefoeofornfonsk snfksnfknsfkn", "Electronics", false, "Dollars", user.Id, "1");
            long productId = product.ProductId;
            UserRegistrationManager.RegisterUser("Correo", "Prueba", 'F', DateTime.Now, "lqs.correo.prueba@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            string buyerEmail = "lqs.correo.prueba@gmail.com";
            User buyer = UserDataAccess.GetUserByEmail(buyerEmail);
            long buyerId = buyer.Id;
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer offer = new Offer();
            offer = OfferManager.MakeAOffer(productId, buyerId, offerPrice, offerDate, message);
            Collection<Offer> expected = null; // TODO: Initialize to an appropriate value
            Collection<Offer> actual;
            actual = OfferDataAccess.GetOffer(productId);
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetOfferByBuyerId
        ///</summary>
        [TestMethod()]
        public void GetOfferByBuyerIdTest()
        {
            string email = "alfaro.natalia.lorena@gmail.com";
            UserRegistrationManager.RegisterUser("Natalia", "Alfaro", 'F', DateTime.Now, "alfaro.natalia.lorena@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            User user = UserDataAccess.GetUserByEmail(email);
            Product product = ProductRegistrationManager.RegisterNewProduct("Toy Story 1 Original DVD", "10", "sbfjksfksb snflsnlfskf sfnlsnflsnflsfsdkoef dojgdnvkdnvkndkvnkdvd snfsnefoeofornfonsk snfksnfknsfkn", "Electronics", false, "Dollars", user.Id, "1");
            long productId = product.ProductId;
            UserRegistrationManager.RegisterUser("Correo", "Prueba", 'F', DateTime.Now, "lqs.correo.prueba@gmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79393047", "4530514");
            string buyerEmail = "lqs.correo.prueba@gmail.com";
            User buyer = UserDataAccess.GetUserByEmail(buyerEmail);
            long buyerId = buyer.Id;
            string offerPrice = "90";
            DateTime offerDate = DateTime.Now;
            string message = "muy buen producto pero el precio un poco caro";
            Offer offer = new Offer();
            offer = OfferManager.MakeAOffer(productId, buyerId, offerPrice, offerDate, message);
            Collection<Offer> expected = null; // TODO: Initialize to an appropriate value
            Collection<Offer> actual;
            actual = OfferDataAccess.GetOfferByBuyerId(buyerId);
            Assert.AreNotEqual(expected, actual);
        }
    }
}
